using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.ServiceBus.Messaging;
using System.Diagnostics;
using GlobalObjects;

namespace SignalRPushNotification
{
    public class WebRole : RoleEntryPoint
    {

        //bool IsStopped = false;
        //const string TopicName = "signalr_topic_finaltopic_0";
        //const string SubscriptionName = "SignalRPushNotification";
        //ChatHub ch = new ChatHub();
        //SubscriptionClient Client;

        public override bool OnStart()
        {
            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            //Creating Subscription Client
            //string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

            //Client = SubscriptionClient.CreateFromConnectionString(connectionString, TopicName, SubscriptionName);

            return base.OnStart();
        }
        //public override void Run()
        //{
        //  //  SubscriptionClient agentSubscriptionClient = SubscriptionClient.Create(TopicName, "SignalRPushNotification");
        //    BrokeredMessage message = null;
        //    while (!IsStopped)
        //    {
        //        try
        //        {
        //            //Receive Message from topic
        //            message = Client.Receive(TimeSpan.FromSeconds(5));
    
        //            if (message != null)
        //            {

        //                //Process the message
        //                Debug.Print("Processing the message from the topic", message.SequenceNumber.ToString());

        //                TempData data = (TempData) message.GetBody<TempData>();



        //                string ex = "Hello";
        //                ch.data = ex;





        //                message.Complete();
        //            }
        //            else
        //            {
        //                //no more messages in the subscription
        //                break;
        //            }
        //        }

        //        catch (MessagingException e)
        //        {
        //            if (!e.IsTransient)
        //            {
        //                Trace.WriteLine(e.Message);
        //                //   throw;
        //            }

                 
        //        }
        //        catch (OperationCanceledException e)
        //        {
        //            if (!IsStopped)
        //            {
        //                Trace.WriteLine(e.Message);
        //                throw;
        //            }
        //        }
        //    }
        //}
        //public override void OnStop()
        //{
        //    // Close the connection to Service Bus Queue
        //    IsStopped = true;
        //    //Client.Close();
        //    base.OnStop();
        //}
    }
}
